#vertex --------------------------------
attribute vec3 position:POSITION;
uniform mat4 game_MatrixVP:VP;
uniform mat4 game_MatrixM:M;
#ifdef UV

attribute vec2 uv:UV;
varying vec2 vuv;
#endif


#ifdef COLOR
attribute vec4 color:COLOR;
varying vec4 vcolor;
#endif
#ifdef NORMAL
attribute vec3 normal:NORMAL;
varying vec3 vnormal;
#endif
#include skinning

void main(void){
    mat4 modelMat =game_MatrixM;
    #ifdef BONE
    #ifdef SKINNING
        modelMat=getBoneMatrix(a_weights,a_indices);
    #endif
    #endif

    
    #ifdef UV
    vuv=uv;
    #endif
    
    #ifdef COLOR
    vcolor=    color;
    #endif
    #ifdef NORMAL
    vnormal=normalize(vec3(modelMat * vec4(normal.xyz, 0.0)));
    #endif
    
    vec4 wp=modelMat*vec4(position,1.0);
    
    gl_Position = game_MatrixVP * wp;
    
    
}
#fragment ------------------------------
uniform vec4 gcolor:COLOR;
#ifdef BASECOLORMAP
uniform sampler2D Texture0:BASECOLORMAP;
#endif

#ifdef UV
varying vec2 vuv;
#endif

#ifdef BASECOLORMAP_UV_SET
uniform vec4 uvset:BASECOLORMAP_UV_SET=vec4(0,0,1,1);
#endif

#ifdef COLOR
varying vec4 vcolor;
#endif

#ifdef NORMAL
varying vec3 vnormal;
#endif

uniform vec3 cameraPos:EYE;

void main(void){
    vec4 baseColor=vec4(1.0,1.0,1.0,1.0);
    #ifdef BASECOLORMAP
        #ifdef UV
            vec2 uv=vuv;
            #ifdef BASECOLORMAP_UV_SET
                uv*=uvset.zw;
                uv+=uvset.xy;
            #endif
            baseColor=texture2D(Texture0,uv);
         #endif
        // baseColor.rgb = pow(baseColor.rgb, vec3(1./2.2));
    #endif

    
    #ifdef COLOR
        baseColor=baseColor*vcolor;
    #endif

    baseColor=baseColor;
    #ifdef select
    float nde=1.-step(0.3,dot(normalize(cameraPos),vnormal));
    baseColor+=gcolor*nde;
    #endif
    
    gl_FragColor = baseColor;
    
    
}
